<?php

function createSign($data, $gymchtKey) {
	$signPars = "";
	ksort($data);
	foreach ($data as $k => $v) {
		if ("" != $v && "pay_sign" != $k) {
			$signPars .= $k . "=" . $v . "&";
		}
	}

	$signPars .= "key=" . $gymchtKey;
	$sign = strtoupper(md5($signPars));
	return $sign;
}

function httpClient($data, $url) {
	$postdata = http_build_query($data);
	try {
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
		$res = curl_exec($ch);
		curl_close($ch);
		return $res;
	} catch (Exception $e) {
		$errorMsg = $e->getMessage();
		return false;
	}
}

function request_form($data = array(), $url = '') {

	if (count($data) > 0) {
		$string = "<form style='display:none;' id='form1' name='form1' method='post' action='" . $url . "'>";
		foreach ($data as $key => $value) {
			if (!isset($value) || is_null($value) || empty($value)) {
				unset($data[$key]);
				continue;
			} else {
				$string .= "<input name='" . $key . "' type='text' value='" . $value . "' />";
			}
		}
		$string .= "</form>";
		$string .= "<script type='text/javascript'>function load_submit(){document.form1.submit()}load_submit();</script>";
		echo $string;
	}
}

function logResult($word = '') {
	$fp = fopen("log.txt", "a");
	flock($fp, LOCK_EX);
	fwrite($fp, "执行日期：" . strftime("%Y%m%d%H%M%S", time()) . "\n" . $word . "\n");
	flock($fp, LOCK_UN);
	fclose($fp);
}
